1 package org.apache.maven.surefire.common.junit48;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.surefire.booter.ProviderParameterNames;
23 import org.apache.maven.surefire.group.match.GroupMatcher;
24 import org.apache.maven.surefire.group.parse.GroupMatcherParser;
25 import org.apache.maven.surefire.group.parse.ParseException;
26 import org.apache.maven.surefire.testset.TestListResolver;
27 import org.junit.runner.manipulation.Filter;
28
29 import java.util.Map;
30 import java.util.Set;
31
32
33
34
35 public class FilterFactory
36 {
37 private final ClassLoader testClassLoader;
38
39 public FilterFactory( ClassLoader testClassLoader )
40 {
41 this.testClassLoader = testClassLoader;
42 }
43
44 public Filter createGroupFilter( Map<String, String> providerProperties )
45 {
46 String groups = providerProperties.get( ProviderParameterNames.TESTNG_GROUPS_PROP );
47 String excludedGroups = providerProperties.get( ProviderParameterNames.TESTNG_EXCLUDEDGROUPS_PROP );
48
49 GroupMatcher included = null;
50 if ( groups != null && groups.trim().length() > 0 )
51 {
52 try
53 {
54 included = new GroupMatcherParser( groups ).parse();
55 }
56 catch ( ParseException e )
57 {
58 throw new IllegalArgumentException(
59 "Invalid group expression: '" + groups + "'. Reason: " + e.getMessage(), e );
60 }
61 }
62
63 GroupMatcher excluded = null;
64 if ( excludedGroups != null && excludedGroups.trim().length() > 0 )
65 {
66 try
67 {
68 excluded = new GroupMatcherParser( excludedGroups ).parse();
69 }
70 catch ( ParseException e )
71 {
72 throw new IllegalArgumentException(
73 "Invalid group expression: '" + excludedGroups + "'. Reason: " + e.getMessage(), e );
74 }
75 }
76
77 if ( included != null && testClassLoader != null )
78 {
79 included.loadGroupClasses( testClassLoader );
80 }
81
82 if ( excluded != null && testClassLoader != null )
83 {
84 excluded.loadGroupClasses( testClassLoader );
85 }
86
87 return new GroupMatcherCategoryFilter( included, excluded );
88 }
89
90 public Filter createMethodFilter( String requestedTestMethod )
91 {
92 return new MethodFilter( requestedTestMethod );
93 }
94
95 public Filter createMethodFilter( TestListResolver resolver )
96 {
97 return new MethodFilter( resolver );
98 }
99
100 public Filter createFailingMethodFilter( Map<Class<?>, Set<String>> failingClassMethodMap )
101 {
102 return new FailingMethodFilter( failingClassMethodMap );
103 }
104
105 public Filter and( Filter filter1, Filter filter2 )
106 {
107 return new AndFilter( filter1, filter2 );
108 }
109 }